package com.spring.demo8;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {

	public void testDemo(){
		ApplicationContext context = new ClassPathXmlApplicationContext("bean8.xml");
		StudentJdbcTemplate studentJDBCTemplate = (StudentJdbcTemplate)context.getBean("studentJdbcTemplate");
		System.out.println("------添加纪录--------" );
		studentJDBCTemplate.create("Zara", 11);
		studentJDBCTemplate.create("Nuha", 2);
		studentJDBCTemplate.create("Ayan", 15);
		System.out.println("------查询结果集--------" );
		List<Student> students = studentJDBCTemplate.listStudents();
		for (Student record : students) {
			System.out.print("ID : " + record.getId() );
			System.out.print(", Name : " + record.getName() );
			System.out.println(", Age : " + record.getAge());
		}
		System.out.println("----更新 -----" );
		studentJDBCTemplate.update(2, 20);
		System.out.println("----Listing Record with ID = 2 -----" );
		Student student = studentJDBCTemplate.getStudent(2);
		System.out.print("ID : " + student.getId() );
		System.out.print(", Name : " + student.getName() );
		System.out.println(", Age : " + student.getAge());
	}
	public static void main(String[] args) {
		new MainApp().testDemo();
	}
}
